﻿$(document).ready(function () {
    //-----------------------------------------------------------

    $('#SelectedCategoryId').change(function () {
        var selectedCategoryId = $(this).val();

            fiilProduceByCategory(selectedCategoryId);

    });
    function fiilProduceByCategory(selectedCategoryId) { 
        var selectProd = $("#SelectedProduceId");
        selectProd.empty();
        $.getJSON("/StoreManager/GetJsonProduceByCategoryId/" + selectedCategoryId,
             null, function (data) {
                 

                 $.each(data, function (index, itemData) {
                     selectProd.append($('<option/>', {
                         value: itemData.id,
                         text: itemData.Text
                     }));
                     $("#SelectedProduceId :first").attr("selected", "selected");
                 });

             });
    }
    //-------------------------------------------------------


    $('#SelectedProduceId').change(function () {
        var selectedProduceId = $(this).val();  
            fiilPackagesByProduce(selectedProduceId);
    });

    function fiilPackagesByProduce(selectedProduceId) {

        $("#SelectedPrepackageId").prop('disabled', false);
        var selectPackage = $("#SelectedPrepackageId");
        selectPackage.empty();

        $.getJSON("/StoreManager/GetJsonPackagesbyProduce/" + selectedProduceId,
             null, function (data) {

                 $.each(data, function (index, itemData) {

                     selectPackage.append($('<option/>', {
                         value: itemData.id,
                         text: itemData.Text
                     }));
                 });
                 $("#SelectedPrepackageId :first").attr("selected", "selected");
             });
    }





});


